package com.lovo.ssc.config;

import com.lovo.util.MQUtil;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;

/**
 * @Auther: lf
 * @Date: 2022/7/8 10:59
 */
public class SellKillMqConfig {
    @Autowired
    CachingConnectionFactory connectionFactory;

    //rabbitmq模板
    @Bean(value = "rabbitTemplate")
    public RabbitTemplate rabbitTemplate() {
        return new RabbitTemplate(connectionFactory);
    }

        @Bean
    public Queue sellKillCheackQueue(){
        return new Queue(MQUtil.sellKillCheackQueue);
    }
    @Bean
    public Queue cancelCheackQueue(){
        return new Queue(MQUtil.cancelCheackQueue);
    }
    @Bean
    public Queue cancelQueue(){
        return new Queue(MQUtil.cancelQueue);
    }
    @Bean
    public Queue sellKillQueue(){
        return new Queue(MQUtil.sellKillQueue);
    }

    @Bean
    public FanoutExchange sellKillFanoutExchange() {
        return new FanoutExchange(MQUtil.directExchangeSellKill);
    }

    @Bean
    public Binding fanoutExchangeToCancelQueue(Queue cancelQueue, FanoutExchange sellKillFanoutExchange) {
        return BindingBuilder.bind(cancelQueue).to(sellKillFanoutExchange);
    }
    @Bean
    public Binding fanoutExchangeToSellKillQueue(Queue sellKillQueue, FanoutExchange sellKillFanoutExchange) {
        return BindingBuilder.bind(sellKillQueue).to(sellKillFanoutExchange);
    }
    @Bean
    public Binding fanoutExchangeToSellKillCheackQueuee(Queue sellKillCheackQueue, FanoutExchange sellKillFanoutExchange) {
        return BindingBuilder.bind(sellKillCheackQueue).to(sellKillFanoutExchange);
    }
    @Bean
    public Binding fanoutExchangeToCancelCheackQueue(Queue cancelCheackQueue, FanoutExchange sellKillFanoutExchange) {
        return BindingBuilder.bind(cancelCheackQueue).to(sellKillFanoutExchange);
    }
}
